<?php
/**
 * Created by PhpStorm.
 * User: Rei
 * Date: 16/5/7
 * Time: 22:20
 * Mail: rei@king.moe
 */

namespace Home\Controller;

use Think\Controller;

class ProfileController extends LoginController
{
    public function index(){
        $notification = D('Subscribe')->getSubNotify();
        $mostcomment = D('Subscribe')->getMostComment();
        $user = D('User')->getUser();
        $subscribe = D("Subscribe")->getSubscribe();

        $this->assign(array('user'=>$user, 'notification'=>$notification, 'mostcomment'=>$mostcomment, 'subscribe'=>$subscribe));
        $this->display('profile/subscribe');
    }

    public function like(){
        $notification = D('Subscribe')->getSubNotify();
        $mostcomment = D('Subscribe')->getMostComment();
        $user = D('User')->getUser();

        $this->assign(array('user'=>$user, 'notification'=>$notification, 'mostcomment'=>$mostcomment));
        $this->display('profile/like');
    }

    public function subscribe(){
        $nid = I('post.tid');
        $action = I('post.action');

        $data = array(
            'code' => 0,
            'message' => '操作失败',
        );

        $result = D('Subscribe')->addSubscribe($nid, $action);

        if($result){
            $data['code'] = 1;
            $data['message'] = '操作成功';
        }

        $this->ajaxReturn($data, 'json');
    }
}